home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_ddd.idb / usr / freeware / share / ddd-3.3.1 / vsllib / tree.vsl.z / tree.vsl
Text File  |  2001-10-09  |  3KB  |  119 lines

  1. // $Id: tree.vsl,v 1.1 2000/06/09 09:27:29 andreas Exp $
  2. // Draw trees
  3.  
  4. // Copyright (C) 1993 Technische Universitaet Braunschweig, Germany.
  5. // Written by Andreas Zeller <zeller@gnu.org>.
  6. // 
  7. // This file is part of DDD.
  8. // 
  9. // DDD is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. // 
  14. // DDD is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. // See the GNU General Public License for more details.
  18. // 
  19. // You should have received a copy of the GNU General Public
  20. // License along with DDD -- see the file COPYING.
  21. // If not, write to the Free Software Foundation, Inc.,
  22. // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. // 
  24. // DDD is the data display debugger.
  25. // For details, see the DDD World-Wide-Web page, 
  26. // `http://www.gnu.org/software/ddd/',
  27. // or send a mail to the DDD developers <ddd@gnu.org>.
  28.  
  29. #include "std.vsl"
  30. #include "slopes.vsl"
  31.  
  32. // Version
  33. tree_version() = "$Revision: 1.1 $";
  34.  
  35. // Tree functions
  36.  
  37. // 1. Vertical Trees
  38.  
  39. // Ratio HEIGHT : WIDTH (1:10)
  40.  
  41. treeheight(width) = vspace(square(width)) / 10;
  42.  
  43. // draw the connections from the root to the children
  44. // return a box of width HROOT * 2 and height HEIGHT
  45. // There will be a line from the center of the upper edge of HSUM + BOX/2 
  46. // to the center of the upper edge of the box
  47.  
  48. vbranch(height, hroot, hsum, hbox2) =
  49. ( height & 
  50.   if hsum & hbox2 < hroot then
  51.         // Box in left half
  52.     hsum & hbox2 & rise() & hroot
  53.   elsif hsum & hbox2 > hroot then
  54.         // Box in right half
  55.     hroot & fall() & hspace(hroot * 2 - hsum - hbox2)
  56.   else
  57.     // Box in center
  58.     hcenter(vrule())
  59.   fi
  60. );
  61.  
  62. vbranches(height, hroot, hsum, box) = 
  63.   vbranch(height, hroot, hsum, hspace(box)/2);
  64.  
  65. vbranches(height, hroot, hsum, box, ...) = 
  66.   vbranches(height, hroot, hsum, box) 
  67. ^ vbranches(height, hroot, hsum & hspace(box), ...);
  68.  
  69.  
  70. // vtree(children...) connects a root with its children.  The edges
  71. // end in the center of the upper edge of the children.
  72.  
  73. _vtree(align, ...) = 
  74.   vbranches(treeheight(hspace(align)), hspace(align)/2, 0, ...)
  75. | hcenter(align);
  76.  
  77. vtree(root) = root;
  78. vtree(root, ...) = 
  79.   hcenter(root) 
  80. | _vtree(halign(...), ...);
  81.  
  82.  
  83.  
  84. // 2. Horizontal Trees
  85.  
  86. // Just the same, only rotated by 90 degrees.
  87.  
  88. treewidth(height) = hspace(square(height)) / 10;
  89.  
  90. hbranch(width, vroot, vsum, vbox2) =
  91. ( width | 
  92.   if vsum | vbox2 < vroot then
  93.     // Box in upper half
  94.     vsum | vbox2 | rise() | vroot
  95.   elsif vsum | vbox2 > vroot then
  96.     // Box in lower half
  97.     vroot | fall() | vspace(vroot * 2 - vsum - vbox2)
  98.   else 
  99.         // Box in center
  100.     vcenter(hrule())
  101.   fi
  102. );
  103.  
  104. hbranches(width, vroot, vsum, box) = 
  105.   hbranch(width, vroot, vsum, vspace(box)/2);
  106.  
  107. hbranches(width, vroot, vsum, box, ...) = 
  108.   hbranches(width, vroot, vsum, box) 
  109. ^ hbranches(width, vroot, vsum | vspace(box), ...);
  110.  
  111. _htree(align, ...) = 
  112.   hbranches(treewidth(vspace(align)), vspace(align)/2, 0, ...)
  113. & vcenter(align);
  114.  
  115. htree(root) = root;
  116. htree(root, ...) = 
  117.   vcenter(root) 
  118. & _htree(valign(...), ...);
  119.